const express = require('express');
const router = express.Router();
const productController = require('../../controllers/product');
const manufacturerController = require('../../controllers/manufacturer');
const buyItemController = require('../../controllers/buy');
// `body-parser` is no longer part of `express`
var bodyParser = require('body-parser');

var jsonParser = bodyParser.json();
var urlencodedParser = bodyParser.urlencoded({ extended: false });

router.get('/manufacturers', jsonParser, manufacturerController.all);
router.get('/manufacturers/:id', jsonParser, manufacturerController.byId);
router.post('/manufacturers', jsonParser, manufacturerController.create);
router.put('/manufacturers/:id', jsonParser, manufacturerController.update);
router.delete('/manufacturers/:id', jsonParser, manufacturerController.remove);

router.get('/products', jsonParser, productController.all);
router.get('/products/:id', jsonParser, productController.byId);
router.post('/products', jsonParser, productController.create);
router.put('/products/:id', jsonParser, productController.update);
router.delete('/products/:id', jsonParser, productController.remove);

router.get('/buy', jsonParser, buyItemController.all)
router.post('/buy', jsonParser, buyItemController.submit)
router.get('/buy/:UserId', jsonParser, buyItemController.byUserId);
router.delete('/buy/:id', jsonParser, buyItemController.remove);


module.exports = router;